import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/4/20 10:26
 */
class Worker extends Thread {
    BlockingQueue<Runnable> queue = null;

    public Worker(BlockingQueue<Runnable> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        while (!Thread.interrupted()) {
            Runnable runnable = null;
            try {
                runnable = queue.take();
                runnable.run();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class MyThreadPool {
    private LinkedBlockingQueue<Runnable> linkedBlockingQueue = new LinkedBlockingQueue<>();

    List<Worker> list = new ArrayList<>();

    public MyThreadPool(int corePoolThread) {
        for (int i = 0; i < corePoolThread; i++) {
            Worker worker = new Worker(linkedBlockingQueue);
            worker.start();
            list.add(worker);
        }
    }

    public void submit(Runnable runnable) {
        try {
            linkedBlockingQueue.put(runnable);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
